package com.itcat.controller;

import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.param.PageParam;
import com.itcat.mysql.pojo.PmsProductCategory;
import com.itcat.mysql.pojo.PmsProductCategoryDto;
import com.itcat.mysql.vo.PmsProductCategoryVo;
import com.itcat.service.PmsProductAttributeCategoryService;
import com.itcat.service.PmsProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-02 18:50
 */
@RestController
@RequestMapping("/productCategory")
public class PmsProductCategoryController {

    @Autowired
    private PmsProductCategoryService pmsProductCategoryService;

    @Autowired
    private PmsProductAttributeCategoryService pmsProductAttributeCategoryService;


    /**
     * 查询所有一级分类及子分类
     * @return
     */
    @GetMapping("/list/withChildren")
    public CommonResult withChildren(){
        List<PmsProductCategoryVo> list = pmsProductCategoryService.withChildren();
        return CommonResult.success(list);
    }


    /**
     * 分页查询分类信息
     * @param parentId
     * @param pageParam
     * @return
     */
    @GetMapping("/list/{parentId}")
    public CommonResult list(@PathVariable Integer parentId, PageParam pageParam){
        CommonPage<PmsProductCategory> page = pmsProductCategoryService.listByParentId(parentId, pageParam);
        return CommonResult.success(page);
    }

    /**
     * 添加商品分类
     * @param
     * @return
     */
    @PostMapping("/create")
//    public CommonResult create(@RequestBody PmsProductCategoryDto dto ){
//        pmsProductCategoryService.create(dto);
//        return CommonResult.success("ok");
//    }
    public CommonResult create(@RequestBody  PmsProductCategoryDto pmsProductCategoryDto){
        pmsProductAttributeCategoryService.create(pmsProductCategoryDto);
        return CommonResult.success();
    }

    /**
     * 修改导航栏状态
     * @param
     * @return
     */
    @PostMapping("/update/navStatus")
    public CommonResult updateNavStatus(Integer ids,Integer navStatus ){
        pmsProductCategoryService.updateNavStatus(ids,navStatus);
        return CommonResult.success("ok");
    }

    /**
     * 修改展示状态
     * @param
     * @return
     */
    @PostMapping("/update/showStatus")
    public CommonResult updateShowStatus(Integer ids,Integer showStatus ){
        pmsProductCategoryService.updateShowStatus(ids,showStatus);
        return CommonResult.success("ok");
    }

    /**
     * 删除商品分类
     * @param parentId
     * @return
     */
    @PostMapping("/delete/{parentId}")
    public CommonResult deleteById(@PathVariable Integer parentId){
        pmsProductCategoryService.deleteById(parentId);
        return CommonResult.success("ok");
    }

    @GetMapping("/{parentId}")
    public CommonResult selectById(@PathVariable Integer parentId){
        PmsProductCategory pmsProductCategory =pmsProductCategoryService.selectById(parentId);
        return CommonResult.success(pmsProductCategory);
    }

}
